<template>
	<view>
		<view class="xm-flex-c xm-justify-center xm-align-content-center xm-brr-20rpx" style="background-color: #FFFFFF;width: 100%;height: auto;align-items: center;padding: 30rpx;box-sizing: border-box;">
			<view class="" style="width: 157rpx;height: 157rpx;border-radius: 157rpx;background-color: #19caff;margin-top: 158rpx;margin-bottom: 30rpx;">
				<image src="https://img0.baidu.com/it/u=19766716,3349517949&fm=26&fmt=auto" mode="widthFix" style="width: 157rpx;border-radius: 157rpx;"></image>
			</view>
			
			<input type="text" value="" v-model="user.user_password" placeholder="输入原密码" style="margin-top: 30rpx;margin-bottom: 30rpx;width: 80%;border: 4rpx #4CD964 solid;padding: 15rpx;border-radius: 20rpx;padding-left: 20rpx;"/>
			
			<input type="text" value="" v-model="user.nes_password" placeholder="输入新密码" style="margin-bottom: 30rpx;width: 80%;border: 4rpx #4CD964 solid;padding: 15rpx;border-radius: 20rpx;padding-left: 20rpx;"/>
		
		    <input type="text" value="" v-model="user.aspassword" placeholder="重复密码" style="margin-bottom: 30rpx;width: 80%;border: 4rpx #4CD964 solid;padding: 15rpx;border-radius: 20rpx;padding-left: 20rpx;"/>
			
			<view class="xm-but" @click="update()" hover-class="but-selct" style="text-align: center;width: 70%;height: 70rpx;line-height: 70rpx;border-radius: 20rpx;margin-top: 60rpx;color: #FFFFFF;">
				确认修改
			</view>
			
			<view class="xm-flex-r xm-justify-between" style="align-items: center;width: 90%;margin-top: 30rpx;margin-bottom: 260rpx;" >
				<!-- <view class="xm-fontsize-15" style="color: #555555;">
					忘记密码
				</view>
				<view class="xm-fontsize-15" style="color: #555555;">
					注册用户
				</view> -->
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{
					user_password:"",
					nes_password:"",
					aspassword:""
				},
				type:undefined,
				id:undefined,
				data:undefined
			}
		},
		onShow() {
			uni.getStorage({
				key:"token",
				success:data=>{
					console.log(data.data);
					this.id = data.data
				}
			})
		},
		computed:{
			ontype(){
				this.type=this.id
				return this.type
			}
			
		},
		methods: {
			update(){
				if(this.user.user_password==""){
					this.$api.msg("请输入原密码")
					return false
				}
				if(this.user.nes_password==""){
					this.$api.msg("请确保新密码输入正确")
					return false
				}
				if(this.user.nes_password!=this.user.aspassword){
					this.$api.msg("重复密码不正确")
					return false
				}
				
				this.$http(this.$url.user.findone, "post",
				{
					user_id:this.id,
					user_password:this.user.use_password
					}, {
					'content-type': 'application/json'
				}).then(res=>{
					this.data = res.data
					console.log(this.data);
					
					
					this.$http(this.$url.user.update, "post",
					{
						user_id:this.id,
						user_password:this.user.nes_password,
						user_accountnumber:this.data.user_accountnumber,
						sex:this.data.sex,
						user_name:this.data.user_name,
						user_mood:this.data.user_mood,
						top_icon:this.data.top_icon
					}, {
						'content-type': 'application/json'
					}).then(res=>{
						// this.data = res.data
						// console.log(this.data);
						console.log(res);
						this.$api.msg("修改成功")
						this.$api.gotoType("back")
					})
				})
			}
			
		}
	}
</script>

<style>
	page{
		background-color:#C0C0C0;
		box-sizing: border-box;
		padding: 30rpx;
	}

.xm-but{
	background:linear-gradient(to right,#26acd4,#d6d6d6);
}
</style>
